const express = require('express')
const app = express()

app.all('/secret', function (req, res, next) {
  console.log('Accessing the secret section ...')
  next() // pass control to the next handler
})

app.get('/', function (req, res) {
  res.send('root')
})

app.get('/about', function (req, res) {
  res.send('about')
})

app.get('/random.text', function (req, res) {
  res.send('random.text')
})

app.get('/ab?cd', function (req, res) {
  res.send('ab?cd')
})

app.get('/ab+cd', function (req, res) {
  res.send('ab+cd')
})

app.get('/ab*cd', function (req, res) {
  res.send('ab*cd')
})

app.get('/ab(cd)?e', function (req, res) {
  res.send('ab(cd)?e')
})

app.get(/a/, function (req, res) {
  res.send('/a/')
})

app.get(/.*fly$/, function (req, res) {
  res.send('/.*fly$/')
})

app.get('/users/:userId/books/:bookId', function (req, res) {
  res.send(JSON.stringify(req.params))
})

app.get('/flights/:from-:to', function (req, res) {
  res.send(JSON.stringify(req.params))
})

app.get('/user/:userId(\\d+)', function (req, res) {
  res.send(JSON.stringify(req.params))
})

app.listen(9000, () => {
  console.log('demo2 run  -->')
})